package com.zhiban.project.controller;

import javax.servlet.http.HttpServletRequest;

import dinamica.Db;
import dinamica.GenericTableManager;
import dinamica.Recordset;

/**
 * 试卷做题自动判卷
 * 
 * @author lxp
 *
 */
public class HandJudgeQuestionController extends GenericTableManager {

	public int service(Recordset inputParams) throws Throwable {
		HttpServletRequest request = this.getRequest();
		String exam_id = request.getParameter("exam_id");
		String ids[] = request.getParameterValues("id");
		String points[] = request.getParameterValues("points");
		addUserQuestion(ids,points);
		String insert = getSQL(getResource("update.sql"), inputParams);
		this.getDb().exec(insert);
		int rc = 0;
		return rc;
	}


	private void addUserQuestion(String ids[],String points[]) throws Throwable {
		Db db = getDb();
		Recordset detail = new Recordset();
		String insertSql = getSQL(getResource("update_point.sql"), detail);
		detail.append("point_get", java.sql.Types.DOUBLE);
		detail.append("id", java.sql.Types.INTEGER);
		int index=0;
		if (ids != null)
		{
			for (String id : ids) {
				detail.addNew();
				String point = points[index++];
				detail.setValue("id", Integer.parseInt(id));
				detail.setValue("point_get", Double.parseDouble(point));
				String cmd = getSQL(insertSql, detail);
				db.addBatchCommand(cmd);
			}
		
		}
		db.exec();
	}

}
